<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Inviter
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 * @version    $Id: Invites.php 2010-07-02 19:54 mirlan $
 * @author     Mirlan
 */

/**
 * @category   Application_Extensions
 * @package    Inviter
 * @copyright  Copyright Hire-Experts LLC
 * @license    http://www.hire-experts.com
 */

class Inviter_Model_DbTable_Invites extends Engine_Db_Table {
	protected $_name = 'inviter_invites';
	
	public function updateInvitation($invitation = array()) {
		if (! is_array ( $invitation ) || count ( $invitation ) == 0)
			return false;
		
		$inviteSelect = $this->select ()->where ( "user_id = '{$invitation['user_id']}' && recipient = '{$invitation['recipient']}' && new_user_id = 0" )->limit ( 1 );
		if (null !== ($inviteRow = $this->fetchRow ( $inviteSelect ))) {
			$inviteRow->sender = $invitation ['sender'];
			$inviteRow->recipient_name = $invitation ['recipient_name'];
			$inviteRow->provider = $invitation ['provider'];
			$inviteRow->code = $invitation ['code'];
			$inviteRow->sent_date = $invitation ['sent_date'];
			$inviteRow->message = $invitation ['message'];
			
			return $inviteRow->save ();
		} else {
			return false;
		}
	}
	
	public function insertInvitation($invitation = array()) {
		if (! is_array ( $invitation ) || count ( $invitation ) == 0)
			return false;
		
		$inviteRow = $this->createRow ();
		$inviteRow->user_id = $invitation ['user_id'];
		$inviteRow->sender = $invitation ['sender'];
		$inviteRow->provider = $invitation ['provider'];
		$inviteRow->recipient = $invitation ['recipient'];
		$inviteRow->recipient_name = $invitation ['recipient_name'];
		$inviteRow->code = $invitation ['code'];
		$inviteRow->sent_date = $invitation ['sent_date'];
		$inviteRow->message = $invitation ['message'];
		
		return $inviteRow->save ();
	}
}
